package leetcode.code1946;

import leetcode.IDebug;

public class Solution implements IDebug {

	public String maximumNumber(String num, int[] change) {
		char[] cs = num.toCharArray();
		for (int i = 0; i < cs.length; i++) {
			int index = cs[i] - '0';
			if (change[index] > index) {
				cs[i] = (char) ('0' + change[index]);
				i++;
				while (i < cs.length) {
					index = cs[i] - '0';
					if (change[index] >= index) {
						cs[i] = (char) ('0' + change[index]);
					} else {
						return new String(cs);
					}
					i++;
				}
			}
		}
		return new String(cs);
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
